const mongoose = require('mongoose')

const schema = new mongoose.Schema({
  username: { type: String }, // 标题
  password: {
    type: String,
    select: false, // 密码在编辑界面时候不要被查出来
    // 自定义值，这里是将密码进行中间处理
    set (val) {
      return require('bcryptjs').hashSync(val, 10)
    }
  },
  phone: {
    type: Number,
    validate: {
      validator:(val) => {
        return /^[1]([3-9])[0-9]{9}$/.test(val);
      },
      message: '{VALUE} is not a valid phone number!'
    },
    required: [true, 'User phone number required']
  }
})

module.exports = mongoose.model('AdminUser', schema)